<?php
namespace app\m\controller;
class Index extends Base{

    function init(){
        #幻灯
        $slides = $this->db->query("select id,url,pic,cat_id,background_color from slide where cat_id in (1) order by sort desc,id desc");
        $slide_temp = [];
        foreach ($slides as $v) {
            if(!isset($slide_temp[$v['cat_id']])) $slide_temp[$v['cat_id']]=[];
            $slide_temp[$v['cat_id']][]=$v;
        }

        #1级分类
        $cat = $this->db->query('select * from goods_cat where parent_id = ? order by sort desc limit 8',[0]);
        #楼层
        foreach($cat as $k => $v){
            // $ids = m('GoodsCat','c')->getAllchildCat($v['id']);
            // if($ids){
            //     $ids = join(',',$ids);
            // }else{
            //     $ids = $v['id'];
            // }
            $rec_id = ",".($k+1).",";
            $cat[$k]['goods']  = $this->db->query("select * from goods where rec_id like '%{$rec_id}%' and status = 0 order by sort limit 12",[]);
        }
        $index = [
            'slide' => $slide_temp,
            'cat'=>$cat,
        ];
        $this->fetch($index);
    }


    function test(){
    }
}
?>
